<?php

namespace app\company\controller;

use app\company\validate\CompanyMenuValidate;
use app\mini\model\CompanyGoods as CompanyGoodsModel;
use app\service\traits\Crud;
use app\company\model\CompanyMenu as CompanyMenuModel;
use app\service\traits\Menu;
use think\facade\Request;
use think\Response;

class CompanyMenu extends Base
{
    private CompanyMenuModel $model;

    use Crud;
    use Menu;

    public function initialize()
    {
        parent::initialize();
        $this->model         = new CompanyMenuModel();
        $this->validateClass = CompanyMenuValidate::class;
        $this->field         = 'id,name,status,path,order_num,parent_id,menu_type,perms,component,query,icon,visible';
        $this->withSearch    = 'name,status';
        $this->append        = 'menu_type_text,status_text';
    }


    public function list(): Response
    {
        $param = request()->param();
        $sql =  $this->model->withSearch($this->withSearch, $param);
        if ($this->field) $sql = $sql->field($this->field);
        $list = $sql->select();
        if(!$list->isEmpty())$list = $this->getTreeData($list->append(explode(',',$this->append))->toArray());
        return $this->success('获取成功', compact('list'));
    }



}